# Based on Python list()
# There are n people, kill every second person,
# starting from the m-th person.
#  def josephus(n, k, m):
#      lista = list(range(1, n+1))
#      i = k-1
#      # 每次都要出列一个人，所有人的总数会随之减少
#      for number in range(n, 0, -1):
#          i = (i+m-1) % number
#          person = lista.pop(i)
#          yield person

def josephus(n, m=2):
    a = list(range(1, n+1))
    i = 0
    for number in range(n, 0, -1):
        i = (i+m-1) % number
        person = a.pop(i)
        yield person

tc = int(input())
for _t in range(tc):
    n, k = map(int, input().strip().split(' '))
    a = tuple(josephus(n))
    print(a[k-1])
